﻿<?php include("conn.php");
mysql_query('SET NAMES UTF8'); 

class MyPrizeBean
{
	public $totalnum;
	public $title;
	public $price;
	public $images;
	public $name;
	public $goodsid;
	public $number;
	public $gname;
	public $numbers;
	public $yuanjia;
	public $brand;
	public $produce;
	public $state;
	public $zongjia;
	public $sd;
	public $sum;
    public $shopid;
	public $ordersid;
	public $tuihuoid;
	public $msg;
	function __construct($totalnum,$title,$price,$images,$name,$goodsid,$number,$gname,$numbers,$yuanjia,$brand,$produce,$state,$zongjia,$sd,$sum,$shopid,$ordersid,$tuihuoid,$msg)
	{
		$this->totalnum    = $totalnum;
		$this->title      = $title;
		$this->price = $price;
		$this->images     = $images;
		$this->name      = $name;
		$this->goodsid    = $goodsid;
		$this->number    = $number;
		$this->gname   = $gname;
		$this->numbers    = $numbers;
		$this->yuanjia    = $yuanjia;
		$this->brand    = $brand;
		$this->produce   = $produce;
		$this->state    = $state;
		$this->zongjia    = $zongjia;
		$this->sd    = $sd;
		$this->sum    = $sum;
		$this->shopid    = $shopid;
		$this->ordersid    = $ordersid;
		$this->tuihuoid    = $tuihuoid;
		$this->msg    = $msg;
	}
}


// 查询平台电话号码
$query = mysql_query("select tel from xitong where id=1");
$xitong = mysql_fetch_assoc($query);
$tel = $xitong[tel];
// 查询平台电话号码 end


	$uid=2;
	$sta=$_REQUEST[sta];
	$prize = array();
if ($sta=='1' || $sta=='7') {
	$rert30=mysql_query("select *from goodsorders where userid='".$_REQUEST[uid]."'  and (state='1' or state='7') order by ordersid desc ");	
}elseif ($sta=='4') {
	$rert30=mysql_query("select *from goodsorders where userid='".$_REQUEST[uid]."'  and (state='4' or state='9') order by ordersid desc ");	
}else {
	$rert30=mysql_query("select *from goodsorders where userid='".$_REQUEST[uid]."'  and state='".$sta."' order by ordersid desc ");	
}
	

	
	while($rowf=mysql_fetch_array($rert30)){
// 订单类型（海淘为0，快购为1）
$type = $rowf[type];
// 订单类型（海淘为0，快购为1） end

$goodsnames='';
$prices='';
$numbers='';
$goodsids='';
$totalnum=0;

$rert31=mysql_query("select *from car where ordersid ='".$rowf[ordersid]."'");
while ($rowf1=mysql_fetch_array($rert31)) {
    	$goodsnames.=','.$rowf1[goodsname];
		$prices.=','.$rowf1[price];
		$numbers.=','.$rowf1[number];
		$totalnum+=$rowf1[number];
		$rert33=mysql_query("select *from goods where goodsid ='".$rowf1[goodsid]."'");
		$rowf3=mysql_fetch_array($rert33);
		$goodsids.=','.$rowf3[goodsid];
		$ime=$rowf3[images];
		$de = array();
		$de=explode("," ,$ime);
		$images=$de[0];
}
$goodsnames=substr($goodsnames, 1);
$prices=substr($prices, 1);
$numbers=substr($numbers, 1);
$goodsids=substr($goodsids, 1);
$goodsids=explode(',', $goodsids);
$yanse=$rowf1[caizhi].$rowf1[caizhi];

$rert34=mysql_query("select SUM(number) as total from car where ordersid ='".$rowf[ordersid]."'");
$rowf4=mysql_fetch_array($rert34);
   
 $rert32=mysql_query("select *from shop where  shopid ='".$rowf[shopid]."'");
$rowf2=mysql_fetch_array($rert32);
// 查找快递公司
$query=mysql_query("select * from express_delivery where id=".$rowf[kuaidi]);
$express_delivery=mysql_fetch_assoc($query);
// 查找快递公司 end

// 查询退货状态
$query = mysql_query("select * from tuihuo where ordersid=".$rowf[ordersid]);
$tuihuo = mysql_fetch_assoc($query);
if ($tuihuo[state]==1) {
	if ($type == 0) {
		$tuihuoTip = "申请退货,待商家审核";
	}elseif ($type == 1) {
		$tuihuoTip = "待平台确认申请";
	}
}elseif ($tuihuo[state]==2){
	//$tuihuoTip = "商家通过退货申请,待平台审核";
	$tuihuoTip = "商家通过退货申请";
}elseif ($tuihuo[state]==3) {
	//$tuihuoTip = "商家拒绝退货申请,待平台审核";
	$tuihuoTip = "商家拒绝退货申请";
}elseif ($tuihuo[state]==4){
	//$tuihuoTip = "平台通过退货申请";
	$tuihuoTip = "商户已确认退货";
}elseif ($tuihuo[state]==5) {
	//$tuihuoTip = "平台拒绝退货申请";
	$tuihuoTip = "厂商已确认收货";
}elseif ($tuihuo[state]==6) {
	$tuihuoTip = "退货完成";
}elseif ($tuihuo[state]==7) {
	$tuihuoTip = "待平台退款";
}
// 查询退货状态
	$st2=1;
	// 	$rert36=mysql_query("select * from goodsimages where  goodsid ='".$rowf3[goodsid]."' and  state='".$st2."' order by id desc limit 0,1");
	// $rowf6=mysql_fetch_array($rert36);


if ($type == 0) {

       if($rowf[state]=="0"){
	   $state="0";
	   // $sds=  "<button onclick=\"delet('".$rowf[ordersid]."')\">
	   $sds=  "<button onclick=\"delets('".$rowf[ordersid]."', this  )\">
				   删除订单
				   </button>
				   <button onClick=\"fukuan('shang_cheng/zhi_fu_win',".$rowf[totalprice].",".$rowf[ordersid].")\">
				   付款
				   </button>";
	   }elseif ($rowf[state]=="1") {
		   $state="1";
		   $sds=  "待商家接单<button onclick=\"tuihuo('".$rowf[ordersid]."','".$rowf[type]."','".$tel."')\" >
				申请退货
				</button>";
	   }
	   else if($rowf[state]=="8"){
	   $state="8";
	   $sds=  "待商家发货<button onclick=\"tuihuo('".$rowf[ordersid]."','".$rowf[type]."','".$tel."')\" >
				申请退货
				</button>";
	   }
	   else if($rowf[state]=="2"){
	   $state="2";
	   $sds=  "<button onclick=\"shouhuo('".$rowf[ordersid]."',this)\">
				  确认收货
				   </button>
				<button onclick=\"open_wu_liu('".$rowf[danhao]."','".$express_delivery[pinyin]."')\">
				  查询物流
				   </button>
				   <button onclick=\"tuihuo('".$rowf[ordersid]."','".$rowf[type]."','".$tel."')\" >
				   申请退货
				   </button>
				   ";
	   }else if($rowf[state]=="3"){
	   $state="3";
	   $sds=  "<button onclick=\"car_btn_all(3,$rowf[shopid],$rowf[ordersid])\">
				   去评价
				   </button>
				   <button onclick=\"tuihuo('".$rowf[ordersid]."','".$rowf[type]."','".$tel."')\" >
				   申请退货
				   </button>
				   ";
	   }
	    else if($rowf[state]=="4" || $rowf[state]=="9"){
	    	if ($rowf[state]=="4") {
	    		$state="4";
	   			$sds=  $tuihuoTip;
	    	}elseif ($rowf[state]=="9") {
	    		$state="9";
	   			$sds=  '待退款';
	    	}
	   
	   }else if($rowf[state]=="5"){
	   $state="5";
	   $sds=  "<button onclick=\"open_wu_liu('".$rowf[danhao]."','".$express_delivery[pinyin]."')\">
				  查询物流
				   </button>
				   <button onclick=\"tuihuo('".$rowf[ordersid]."','".$rowf[type]."','".$tel."')\" >
				   申请退货
				   </button>
				   交易完成
				   ";
		}elseif ($rowf[state]=="6") {
		$state="6";
		$sds=  "订单关闭";
		}elseif ($rowf[state]=="7") {
		$state="7";
		$sds=  "<button onclick=\"tuihuo('".$rowf[ordersid]."','".$rowf[type]."','".$tel."')\" >
	   申请退货
	   </button>
		";
		}
}elseif ($type == 1) {
 	if($rowf[state]=="0"){
	   $state="0";
	   // $sds=  "<button onclick=\"delet('".$rowf[ordersid]."')\">
	   $sds=  "<button onclick=\"delets('".$rowf[ordersid]."', this  )\">
				   删除订单
				   </button>
				   <button onClick=\"fukuan('shang_cheng/zhi_fu_win',".$rowf[totalprice].",".$rowf[ordersid].")\" >
				   付款
				   </button>";
	}else if ($rowf[state]=="1") {
		$state="1";
		$sds=  "待商家接单<button onclick=\"tuihuo('".$rowf[ordersid]."','".$rowf[type]."','".$tel."')\" >
				申请退货
				</button>";
	}else if($rowf[state]=="4" || $rowf[state]=="9"){
	    	if ($rowf[state]=="4") {
	    		$state="4";
	   			$sds=  $tuihuoTip;
	    	}elseif ($rowf[state]=="9") {
	    		$state="9";
	   			$sds=  '待退款';
	    	}
	   
	}else if($rowf[state]=="8" ){
	   $state="8";
	   $sds=  "待商家发货<button onclick=\"tuihuo('".$rowf[ordersid]."','".$rowf[type]."','".$tel."')\" >
				申请退货
				</button>";
	}else if($rowf[state]=="3"){
		$state="3";
		$sds=  "<button onclick=\"car_btn_all(3,$rowf[shopid],$rowf[ordersid])\">
		去评价
		</button>
		<button onclick=\"tuihuo('".$rowf[ordersid]."','".$rowf[type]."','".$tel."')\" >
		申请退货
		</button>
		";
	}else if($rowf[state]=="5"){
	   $state="5";
	   $sds=  "完成";
	}elseif ($rowf[state]=="6") {
		$state="6";
		$sds=  "订单关闭";
	}
}
// 如果sta=4即订单状态为退货状态,需要查询退货id
$query = mysql_query("select * from tuihuo where ordersid=".$rowf[ordersid]);
$tuihuo = mysql_fetch_assoc($query);
if (is_array($tuihuo)) {
	$tuihuoid=$tuihuo[id];
}else{
	$tuihuoid=0;
}
// 如果sta=4即订单状态为退货状态,需要查询退货id

			$prize[] = new MyPrizeBean($totalnum,$goodsnames,$prices,$images,$rowf2['name'],$goodsids[0],$numbers,$rowf3['name'],$rowf['numbers'],$rowf3['yuanjia'],$rowf3['brand'],$yanse,$state,$rowf['totalprice'],$sds,$rowf4[total],$rowf2['shopid'],$rowf[ordersid],$tuihuoid,$rowf[msg]);
		
	}

echo json_encode($prize);


?>